package config

import (
	"fmt"
	"os"
)

type Env int

const (
	ENV_DEV Env = iota
	ENV_TEST
	ENV_PROD
)

var config *Config = nil

func Get() *Config {
	return config
}
func Init(v *Config) error {
	config = v
	config.WorkPath, _ = os.Getwd()
	fmt.Println("global config load success1")
	return nil
}

type Config struct {
	Env      Env
	Port     int
	WorkPath string
}

/*
func (config *Config) Print() {
	env := "unkown"
	if config.Env == ENV_DEV {
		env = "dev"
	} else if config.Env == ENV_TEST {
		env = "test"
	} else if config.Env == ENV_PROD {
		env = "prod"
	}
	fmt.Println(strings.Join([]string{
		"============================",
		"[GLOBAL CONFIG]",
		"ENV : " + env,
		"Port : " + fmt.Sprint(config.Port),
		"WorkPath : " + fmt.Sprint(config.WorkPath),
	}, "\n"))
}
*/
/*

func loadConfig() {
	if err := viper.ReadInConfig(); err != nil {
		fmt.Println("读取配置文件出错", err)
		os.Exit(-1)
		return
	}
	viper.Unmarshal(&Config)
	PrintConfig()
}

var Subject = observer.Subject[GlobalConfig]{}

type ConfigProps struct {

}

func Init(
	name string,
	configType string,
	path string,
) {
	Config.WorkPath, _ = os.Getwd()

	viper.SetConfigName(name)
	viper.SetConfigType(configType)
	viper.AddConfigPath(filepath.Join(Config.WorkPath, "config"))

	loadConfig()

	viper.WatchConfig()
	viper.OnConfigChange(func(e fsnotify.Event) {
		loadConfig()
		Subject.Notify(Config)
	})
}
*/
